package org.tamal.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import org.tamal.model.User;

/**
 * This validator validates a User.
 * @author Tamal Kanti Nath
 */
public final class UserValidator implements Validator {

    @Override
    public boolean supports(Class<?> candidate) {
        return User.class.isAssignableFrom(candidate);
    }

    @Override
    public void validate(Object obj, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName",
                "required", "Username is required.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
                "required", "Password is required.");
    }
}
